<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //递归
        //求1~n之和
        function sumN(n){
            if(n==1){
                return 1
            }else{
                return n+sumN(n-1);
        }
        }
        console.log(sumN(10000));

        function yanghui(n){
            for(i=0;i<n;i++){
                for(j=0;j<=i;j++){
                    document.write(num(i,j)+"&nbsp")
                }
                document.write("<br>")
            }
            function num(i,j){
                if(j==0 || j==i){
                    return 1;
                }else{
                    return num(i-1,j-1)+num(i-1,j);
                }
            }
        }
        yanghui(20)
        //使用数组打印40阶杨辉三角，与递归对比，体会一下算法的魅力。 
    </script>
</body>
</html>